///
/// Override DataBind(),call base Databind() to populate the UI
/// controls using the DataSource and then initilize the values of
/// field control
///
public override void DataBind()
{
// Call base.DataBind()
base.DataBind();
if (!this.Page.IsPostBack)
{
// Get the key from the URL.
string keyFromUrl = this.Page.Request.QueryString["Initfrom${Table Name}"];
// keyFromUrl variable will contain a parameter string as follows
// InitfromEmployees=4 or InitfromEmployees=<...xml parameter definition...>
// set this url for New button in a page with table control.
if (keyFromUrl != null && (keyFromUrl.Trim().Length > 0))
{
// Create the where clause.
WhereClause wc = new WhereClause();
string recId = keyFromUrl;
if (KeyValue.IsXmlKey(recId))
{
// Key are typically passed as XML structures to handle composite keys.
// If XML, then add a Where clause based on the Primary Key in the XML.
KeyValue pkValue = KeyValue.XmlToKey(recId);
wc.iAND(${${Table Name}ClassName}.${Primary Key}, BaseFilter.ComparisonOperator.EqualsTo, pkValue.GetColumnValue(${${Table Name}ClassName}.${Primary Key}).ToString());
}
else
{
// The URL parameter contains the actual value, not an XML structure.
wc.iAND(${${Table Name}ClassName}.${Primary Key}, BaseFilter.ComparisonOperator.EqualsTo, recId);
}
// Get existing record based on primary key.
${${Table Name}RecordClassName}[] rec = ${${Table Name}ClassName}.GetRecords(wc, null, 0, 2);
if (rec.Length > 0)
{
// Populate each field value based on existing record's values.
this.${Initialization Field Control}.Text = rec[0].${Initialization Field}.ToString();
}
}
}
}
|